/*
 * $Id: EntityManagerProvider.java 14 2014-08-15 11:50:17Z ratking $
 *
 * Copyleft (C) 2014 RatKing. All wrongs reserved.
 */
package cn.ratking.demo.jaws6.resource;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.slf4j.Logger;

/**
 * 实体管理器提供者
 */
@Dependent
public class EntityManagerProvider {

    @Inject
    private transient Logger log;
    @PersistenceContext(unitName = "jawsPU")
    private EntityManager em;

    /**
     * 生产实体管理器
     *
     * @return 实体管理器
     */
    @Produces
    @JawsPU
    public EntityManager createPtcpEntityManager() {
        log.info("获得@JawsPU实体管理器em");
        return em;
    }

//    /**
//     * 销毁实体管理器
//     *
//     * @param em 实体管理器
//     */
//    public void disposePtcpEntityManager(@Disposes @JawsPU EntityManager em) {
//        log.info("将销毁@JawsPU实体管理器em, em.isOpen()=" + em.isOpen());
//        // work around what I suspect is a bug in Weld
//        if (em.isOpen()) {
//            em.close();
//            log.info("已销毁@JawsPU实体管理器em");
//        }
//    }
}
